{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'map.html'"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "import pandas as pd \n",
    "import plotly.graph_objects as go\n",
    "import plotly as py\n",
    "\n",
    "pyplt = py.offline.plot\n",
    "\n",
    "china_ncp=pd.read_excel('dat/ncp_map.xlsx')\n",
    "\n",
    "china_ncp.head()\n",
    "with open(r'dat/china.json',encoding='utf-8')as f:\n",
    "    china_geo=json.load(f)\n",
    "token='pk.eyJ1Ijoic3l2aW5jZSIsImEiOiJjazZrNTcwY3kwMHBrM2txaGJqZWEzNWExIn0.tLQHY_OoiR2NMxnYHXUBAA'\n",
    "fig=go.Figure(go.Choroplethmapbox(geojson=china_geo,locations=china_ncp['FIPS'],z=china_ncp['province_confirmedCount'],name='NCP',\n",
    "                                  hovertext=china_ncp['Provinces'],hoverinfo='text+z',zmax=2000,zmin=0,text=china_ncp['province_curedCount'], \n",
    "                                  colorscale='YlOrRd',marker_line_width=0.5,marker_line_color='rgb(169,164,159)'))\n",
    "fig.update_layout(mapbox={'accesstoken':token,'center':{'lon':109.469607,'lat':37.826077},'zoom':3.6},\n",
    "                 title={'text':'疫情地图','xref':'paper','x':0.5},\n",
    "                 margin={'l':10,'r':0,'t':50,'b':10})\n",
    "fig.data[0].hovertemplate =  '<b>Province</b>: <b>%{hovertext}</b>'+\\\n",
    "                              '<br> <b>确诊人数 </b>: %{z}<br>'+\\\n",
    "                              '<br> <b>治愈人数 </b>: %{text}<br>'\n",
    "                            \n",
    "pyplt(fig, filename='map.html')\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
